package com.czf.alibaba_seata_consumer.service;

import com.czf.alibaba_api.busi.IBusiService;
import com.czf.alibaba_api.staff.IStaffService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * @author: create by czf
 * @version: v1.0
 * @description: com.czf.alibaba_seata_consumer.service
 * @date: 2020-03-28 15:49
 **/
@Service
public class HoldServiceImpl implements IHoldService{

    @Reference
    IBusiService bs;

    @Reference
    IStaffService ss;

//    @GlobalTransactional(name = "czf_groups", rollbackFor = Exception.class)
    @GlobalTransactional(timeoutMills = 300000)
    @Override
    public String getAll() {
        String xid = RootContext.getXID();

        System.out.println("事务ID：" + xid);
        StringBuilder sb = new StringBuilder();
        sb.append(bs.getAllBusi());
        String str = null;

        System.out.println("1------------------");
//        if (true) {
//            throw new RuntimeException("测试抛异常后，分布式事务回滚！");
//        }
//        System.out.println(str.toString());
        System.out.println("2------------------");


        sb.append("-----------");
        sb.append(ss.getAllStaff());
        return sb.toString();
    }
}
